From 1a08d2cf9196e2679afd004f6042e7ba3941da32 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Wed, 28 Jun 2017 14:02:25 +0200 Subject: [PATCH] "main" can be valid name for binary again, improve test --- src/cargo/util/toml.rs | 8 ++------ tests/build.rs | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index b70b102f7..d1793cfc9 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -531,12 +531,8 @@ fn inferred_bin_targets(name: &str, layout: &Layout) -> Vec { // if the path ends with main.rs it is probably a directory, but it can also be // a file directly inside src/bin if parent.ends_with("src/bin") { - // This would always return name "main" - // Fixme: Is this what we want? based on what @matklad said, I don't think so - // bin.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string()) - - // This seems to be the right solution based on the inferred_bin_paths function - Some(name.to_string()) + // This will always return name "main" + bin.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string()) } else { parent.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string()) } diff --git a/tests/build.rs b/tests/build.rs index bbc1ca1b1..b5ab977cc 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -3310,8 +3310,11 @@ fn dir_and_file_with_same_name_in_bin() { .file("src/bin/foo.rs", "fn main() {}") .file("src/bin/foo/main.rs", "fn main() {}"); - // TODO: This should output the error from toml.rs:756 - assert_that(p.cargo_process("build"), execs().with_status(101)); + assert_that(p.cargo_process("build"), + execs().with_status(101) + .with_stderr_contains("\ +[..]found duplicate binary name foo, but all binary targets must have a unique name[..] +")); } #[test] -- 2.30.2